package com.lrr.community.dto;

import lombok.Data;

import java.util.LinkedList;
import java.util.List;

@Data
public class PaginationDTO {
    private List<QuestionDto> questions;
    private boolean showPrePage;
    private boolean showFirstPage;
    private boolean showNextPage;
    private boolean showEndPage;
    private Integer page;
    private Integer totalPage;

    // 当前显示的页码数
    private List<Integer> pages = new LinkedList<>();


    public void setPagination(Integer totalCount, Integer page, Integer size) {

        this.page = page;
        pages.add(page);
        for(int i=1;i<=3;i++){
            if(page-i>0)
                pages.add(0,page-i);
            if(page+i<=totalPage)
                pages.add(page+i);
        }
//        System.out.println(page+", "+totalPage+", "+totalCount);
//        System.out.println(pages);

        // 是否展示上一页的按钮
        showPrePage = page == 1 ? false : true;
        // 是否展示下一页的按钮
        showNextPage = page == totalPage ? false : true;

        // 是否展示第一页的按钮
        showFirstPage = pages.contains(1) ? false : true;
//        System.out.println(showFirstPage+", "+showPrePage);
//        System.out.println((page==1)+", "+pages.contains(1));
        // 是否展示最后一页的按钮
        showEndPage = pages.contains(totalPage) ? false :true;


    }
}
